package io.renren.modules.member.dao;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.modules.member.vo.ExamVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface CommQueryDao {

    @Select("<script>" +
            "SELECT e.id, e.exam_date AS examDate, e.student_code as studentCode, m.`name`, m.birthday, m.sex," +
            " e.age, e.height, e.weight, e.bmi, e.shape_level AS shapeLevel, e.lead_up as leadUp,e.lead_up_score AS leadUpScore,e.crank_arm AS crankArm," +
            " e.crank_arm_score AS crankArmScore,e.push_up AS pushUp,e.push_up_score AS pushUpScore,e.sit_up AS sitUp,e.sit_up_score AS sitUpScore," +
            " e.snake_run as snakeRun,e.snake_run_score AS snakeRunScore," +
            " e.middle_run as middleRun,e.middle_run_score as middleRunScore,e.total_score as totalScore,e.level,e.create_date as createDate,e.update_date as updateDate " +
            " FROM physical_exam e left join steel_member m ON m.student_code = e.student_code " +
            "<where> " +
            " <if test=\"p.name != null and p.name !=''\"> " +
            " AND m.name = #{p.name} " +
            " </if>" +
            " <if test=\"p.examDate != null and p.examDate !=''\"> " +
            " AND e.exam_date = #{p.examDate} " +
            " </if>" +
            " <if test=\"p.studentCode != null and p.studentCode !=''\"> " +
            " AND e.student_code = #{p.studentCode} " +
            " </if>" +
            " <if test=\"p.shapeLevel != null and p.shapeLevel !=''\"> " +
            " AND e.shape_level = #{p.shapeLevel} " +
            " </if>" +
            " <if test=\"p.level != null and p.level !=''\"> " +
            " AND e.level = #{p.level} " +
            " </if>" +
            "</where>" +
            " ORDER BY e.exam_date DESC " +
            "</script>")
    List<Map<String, Object>> findPageExam(Page page, @Param("p") Map<String, Object> param);

    @Select("<script>" +
            "SELECT e.id, e.exam_date, e.student_code, m.`name`, m.birthday, m.sex," +
            " e.age, e.height, e.weight, e.bmi, e.shape_level, e.lead_up,e.lead_up_score,e.crank_arm," +
            " e.crank_arm_score,e.push_up,e.push_up_score,e.sit_up,e.sit_up_score,e.snake_run,e.snake_run_score,e.middle_run,e.middle_run_score,e.total_score,e.level,e.create_date,e.update_date " +
            " FROM physical_exam e left join steel_member m ON m.student_code = e.student_code " +
            "<where> " +
            " <if test=\"name != null and name !=''\"> " +
            " AND m.name = #{name} " +
            " </if>" +
            " <if test=\"examDate != null and examDate !=''\"> " +
            " AND e.exam_date = #{examDate} " +
            " </if>" +
            " <if test=\"studentCode != null and studentCode !=''\"> " +
            " AND e.student_code = #{studentCode} " +
            " </if>" +
            " <if test=\"shapeLevel != null and shapeLevel !=''\"> " +
            " AND e.shape_level = #{shapeLevel} " +
            " </if>" +
            " <if test=\"level != null and level !=''\"> " +
            " AND e.level = #{level} " +
            " </if>" +
            "</where>" +
            " ORDER BY e.exam_date DESC " +
            "</script>")
    List<ExamVO> findAllExam(Map<String, Object> param);
}
